import scrapy
from scrapy.http import HtmlResponse
from scrapy import Request,Selector
from ssqSpider.items import DoubanMovieItem


class DoubanSpider(scrapy.Spider):
    name = "douban"
    allowed_domains = ["douban.com"]
    start_urls = ["https://movie.douban.com/top250?start=0&filter="]

    def parse(self, response:HtmlResponse):
        # #print(response.text)
        # # 1使用Selector
        # # sel=Selector(response)
        # # list_items=sel.css('#content > div > div.article > ol > li')
        # list_items=response.css('#content > div > div.article > ol > li')
        # for list_item in list_items:
        #     item=DoubanMovieItem()
        #     item['title']=list_item.css('span.title::text').extract_first()
        #     item['stars']=list_item.css('span.rating_num::text').extract_first()
        #     item['subject']=list_item.css('span.inq::text').extract_first()
        #     yield item

        # # 2使用xpath
        # list_items=response.xpath('//*[@id="content"]/div/div[1]/ol/li')
        # for list_item in list_items:
        #     item=DoubanMovieItem()
        #     item['title']=list_item.xpath('//span[@class="title"]/text()').extract_first()
        #     item['stars']=list_item.xpath('//span[@class="rating_num"]/text()').extract_first()
        #     item['subject']=list_item.xpath('//span[@class="inq"]/text()').extract_first()
        #     yield item
        pass
